#!/usr/bin/python3
# -*- coding: utf-8 -*-

# @desc   : 用python实现求笛卡尔积
import itertools
import re

import requests
from lxml import etree


class cartesian(object):
    def __init__(self):
        self._data_list = []

    def add_data(self, data=[]):  # 添加生成笛卡尔积的数据列表
        self._data_list.append(data)

    def build(self):  # 计算笛卡尔积
        for item in itertools.product(*self._data_list):
            print(item)


if __name__ == "__main__":
    # car=cartesian()
    # car.add_data([1,2,3,4])
    # car.add_data([5,6,7,8])
    # car.add_data([9,10,11,12])
    # car.build()

    # list = [1, 2, 3]
    #
    # new_list = []
    # for i in range(1, len(list) + 1):
    #     for iter in itertools.combinations(iterable=list, r=i):
    #         print(iter)
    #         new_list.append(iter)
    # print(new_list)
    # print(len(new_list))
    #
    str = '<input type="hidden" name="_csrf_token" value="nNgvm6o91xrXD0WVB4jtMDBvpXW-rAS6KVDq7FuPTIw">\n'
    fina = re.findall('_csrf_token" value="(.+?)">', str)
    print(fina)

    data = {
        "_username": "1125176972@qq.com",
        "_password": "abc123456d",
        "_remember_me": "on",
        "youka_online_protocol": 0,
        "_target_path": "http://www.iyouka.com",
        "_csrf_token": "ZTgcsVNw4Y65A6FGv1vHoqgzxQrQLXMQMWXMRRgHIqs",
        "auto": 0
    }
    headers = {'cookie': "PHPSESSID=c37e5261961f60b241dcb90ee4088202;"}
    print('test_headers:', headers)
    res = requests.post(url='http://www.iyouka.com/login_check', data=data, headers=headers, verify=False)
    # print(res.text)
    log_out = etree.HTML(res.text).xpath('//div[@class="user-dropdown__logout"]/a/text()')
    print(log_out)

